@foreach($nList as $_time=>$_list)

    <!--- 列表 --->

    {{--<div class="h1">
        <img src="{{$style_host}}atw/images/calendar.png"/>{{$_time}}
    </div>--}}
    @foreach($_list as $_row)
        <div class="line article-{{$_row['id']}} @if($_row['is_major']) bred @endif">
            <div class="blue" title="{{date('Y-m-d H:i', $_row['ctime'])}}"
                 data-stamp="{{$_row['ctime']}}">{{date('H:i', $_row['ctime'])}}</div>

            <!--- 没有图片  --->
            @if(empty($_row['pic']) || empty($_row['en_title']))
                <div class="con">
                    @if($_row['en_title'])
                        <div class="name fw700">
                            <a href="{{atwUrl('article', $_row)}}" target="_blank">{{$_row['en_title']}}</a>
                        </div>
                    @endif
                    @if($_row['en_description'])
                        <div class="tips">
                            <a href="{{atwUrl('article', $_row)}}" target="_blank">{{$_row['en_description']}}</a>
                        </div>
                    @endif
                </div>
            @else
            <!--- 有图片  --->
                <div class="con_img">
                    @if($_row['en_title'])
                        <div class="name fw700">
                            <a href="{{atwUrl('article', $_row)}}" target="_blank">{{$_row['en_title']}}</a>
                        </div>
                    @endif
                    @if($_row['en_description'])
                        <div class="tips">
                            <a href="{{atwUrl('article', $_row)}}" target="_blank">{{$_row['en_description']}}</a>
                        </div>
                    @endif
                </div>
                <div class="img">
                    <a href="{{atwUrl('article', $_row)}}" target="_blank"><img src="{{$_row['pic']}}"/></a>
                </div>
            @endif

        </div>
    @endforeach
@endforeach

<script>
    // 将时间戳转换为日期格式并展示
    $(".line .blue").each(function (index, element) {
        let stamp = $(this).data('stamp');
        $(this).text(getDateTime(stamp*1000, 'hh:mm'))
        //$(this).text(getDateTime(stamp, 'time'))
    });

    // 将时间戳转换为日期格式
    function getDateTime(stamp, format = 'time') {
        var date = new Date(stamp)
        var YY = date.getFullYear();
        var MM = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
        var DD = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
        var hh = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours());
        var mm = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes());
        var ss = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
        if (format == 'time') {
            return hh + ':' + mm + ':' + ss;
        } else if (format == 'datetime') {
            return YY + '-' + MM + '-' + DD + ' ' + hh + ':' + mm + ':' + ss;
        } else if (format == 'date') {
            return YY + '-' + MM + '-' + DD;
        } else if (format == 'hh:mm') {
            return hh + ':' + mm;
        }
    }
</script>

@if($page==1)
    <div id="max_time" style="display: none;">{{$max_time}}</div>
    <div id="max_id" style="display: none;">{{$max_id}}</div>
    <div id="cate_id" style="display: none;">{{$cate_id}}</div>

    <script>
        // 加载最新 本地不加载 不方便测试与修改
        setInterval(function () {
            let max_id = $("#max_id").text()
            let cate_id = $("#cate_id").text()
            let max_time = $("#max_time").text()
            let data = {max_id: max_id, cate_id: cate_id, max_time: max_time};
            toCateNewsest('/cate/newest', data)
        }, 1000)


        // 加载最新：自动加载最新
        function toCateNewsest(url, data) {
            console.log('加载更多', url);
            console.log('加载更多', data);
            $.ajax({
                type: 'post',
                url: url,
                // data: 'name=zhangsan&age=20'
                data: JSON.stringify(data),
                contentType: 'application/json',
                dataType: "json",
                // contentType: 'application/x-www-form-urlencoded',
                // 这个方法在请求发送前调用，可以用来做表单校验、用来做请求等待动画的调用
                /*beforeSend: function () {
                    // 返回false是取消发送
                    return false
                },*/
                // 会自动帮我们把返回的数据根据响应头设置的类型进行转换好（也就是会自动转成json对象）
                success: function (res) {
                    console.log('执行结果', res)
                    if (res.code == 400) {
                        alert(res.msg)
                    } else {
                        $("#news_list").prepend(res.data.html)
                        if (res.data.max_id > 0) {
                            $("#max_id").text(res.data.max_id)
                        }
                    }
                },
                // xhr是ajax对象
                error: function (xhr) {
                }
            });
        }
    </script>
@endif
